#ifndef MARKDOWN_EDITOR_1_PARSER_H
#define MARKDOWN_EDITOR_1_PARSER_H
#include <iostream>
#include <map>
#include <list>
#include <vector>
#include <sstream>
#include <fstream>
#include <utility>
#include <regex>
#include "Tree.h"
using namespace std;
template <class T>
class Tree;
//string GbkToUtf8(const char *src_str);
//string Utf8ToGbk(const char *src_str);
const map<string, string> htmlWords = {
    {"<", "&lt"},
    {">", "&gt"},
    {"&", "&amp"},
    //{"\"", "&quot"},
    {"'", "&#39"},
};
void replace(string &a, const string &substr, const string &format);
void htmlOptmize(string &a);
using namespace std;
enum types
{
    QUOTEBLOCK = 0,
    ULIST,
    OLIST,
    CODEBLOCK,
    TITLE,
    //URL,
    ITALIC,
    STRONG,
    CODE,
    LINE,
    PARA,
    PHOTO,
    LINK,
    BOLD,
    TABLE
};

vector<string> listCut(string lst);
int Counter(string &s, char c);
class Parser;

class Lexer
{
    friend Parser;

public:

    explicit Lexer(string raw);

    vector<string> outPut();

    void tokenize(string raw);

    void print(); //Only for dubug use.

private:
    std::vector<string> tokens;
};

class Parser
{
public:
    int parseOneLine(int now,string* product, vector<string> aligins = {});

    explicit Parser(vector<string> tokens, bool code = false);

    void parseList(Tree<string> *t,string* product);

    void smallParse(string temp,string* product);

    void tinyParse(string a,string* product);

    void parseCheat(string name, string target, string css = "github.css");

private:
    vector<string> tokens;
    bool code = false;
    bool env[14]{};
};

#endif //MARKDOWN_EDITOR_1_PARSER_H
